﻿using static CyberU;
using static CyberU.UI;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using System;
using UnityEngine;
using System.Runtime.InteropServices;

public class ApplicationTrasparent : MonoBehaviour
{
    [DllImport("user32.dll")]
    private static extern IntPtr GetActiveWindow();

    [DllImport("user32.dll")]
    private static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);

    [DllImport("user32.dll")]
    private static extern bool SetLayeredWindowAttributes(IntPtr hWnd, uint crKey, byte bAlpha, uint dwFlags);

    [DllImport("user32.dll")]
    private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

    public const int GWL_EXSTYLE = -20;
    public const uint WS_EX_LAYERED = 0x00080000;
    public const uint WS_EX_TRANSPARENT = 0x00000020;
    public const uint WS_EX_TOPMOST = 0x00000008;
    public const uint LWA_ALPHA = 0x00000002;
    public const uint SWP_NOSIZE = 0x0001;
    public const uint SWP_NOMOVE = 0x0002;
    // const IntPtr HWND_TOPMOST = (IntPtr)(-1);
    public  readonly IntPtr HWND_TOPMOST = new IntPtr(-1);

    void Start()
    {
        // return;
        Camera.main.backgroundColor = UI.EditorBackgroundColor;
        // print(UI.EditorBackgroundColor);
        // print(2);
#if !UNITY_EDITOR
        // int extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
        // SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TOPMOST);
        // SetLayeredWindowAttributes(hWnd, 0, 30, LWA_ALPHA);
        // SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);


        // IntPtr hWnd = GetActiveWindow();
        // SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_LAYERED | WS_EX_TRANSPARENT);
        // Camera.main.backgroundColor = Color.clear;
#endif
        
        // Camera.main.backgroundColor = new Color(0,0,0,0);
        Camera.main.clearFlags = CameraClearFlags.SolidColor;
    }
}